-- Soglia di hp per iniziare a curarsi Default: UO.MaxHits per curare appena manca 1hp
hits = UO.MaxHits 

--Inizio script
bandagetype = 3617 

function main()
  local items
  nBende = ContaBende()    
  while true do
    wait(1)
    while UO.Hits < UO.MaxHits or string.find(UO.CharStatus,"C") do
      if ContaBende() >= 1 then
        WaitCursor()
        UO.Macro(58,0)
        if ContaBende() <= 10 then
          UO.SysMessage("hai solo " .. ContaBende() .. " bende!",233)
          end 
        counter() 
      end 
    end
  end
end  
 

function counter()
local timer = 11
if UO.Dex % 20 > 0 then 
  timer = ( 11 -  ( UO.Dex - (  UO.Dex % 10 ) ) / 20 ) + 0.5
else 
  timer = ( 11 -  ( UO.Dex - (  UO.Dex % 10 ) ) / 20 )
end
  for i=timer,1,-1 do
    UO.ExMsg(UO.CharID,3,375,tostring(i))
    wait(1000)
  end 
end

function ContaBende()
local cnt = UO.ScanItems(true)-1 
  for i=0,cnt do
    local id,type,kind,contid,x,y,z,stack,rep,col = UO.GetItem(i)
    if contid == UO.BackpackID and type == bandagetype and stack > 0 then
     idbende = id
     return stack 
    end
  end
return false
end

function WaitCursor(t)
if t == nil then
  timeout = 1000 + getticks ()
else 
  timeout = t + getticks ()
  end
while UO.TargCurs == true and timeout > getticks() do 
   wait (5)
   if timeout <= getticks() then
      return false
      end 
   end
return true 
end

main()